package com.btex.app.treaty;

import android.view.View;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.CoinsInfo;
import com.btex.app.tools.SharedPreferencesUtil;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/26
 * @time 下午11:27
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class CoinsAdapter extends BaseQuickAdapter<CoinsInfo.DataBean.BalancesBean, BaseViewHolder> {

    public CoinsAdapter() {
        super(R.layout.item_property_fragment);
    }

    @Override
    protected void convert(BaseViewHolder helper, CoinsInfo.DataBean.BalancesBean item) {

        SharedPreferencesUtil sharedPreferences = SharedPreferencesUtil.getSharedPreferences(MyApplication.getContextObject());
        boolean isEngilsh = sharedPreferences.getBoolean("isEngilsh", false);

        TextView item_trade_list_zhuan_ru = (TextView) helper.getView(R.id.item_trade_list_zhuan_ru);
        TextView item_trade_list_zhuan_chu = (TextView) helper.getView(R.id.item_trade_list_zhuan_chu);
        TextView treaty_behavior_tv_change = (TextView) helper.getView(R.id.treaty_behavior_tv_change);
        treaty_behavior_tv_change.setVisibility(View.VISIBLE);
        item_trade_list_zhuan_ru.setVisibility(View.GONE);
        item_trade_list_zhuan_chu.setVisibility(View.GONE);


        helper.setText(R.id.item_trade_list_name, item.getCoin());
        helper.setText(R.id.item_trade_list_tv_money_n_type, "委托保证金:");
        helper.setText(R.id.item_trade_list_tv_total_money_type, "仓位保证金:");
        helper.setText(R.id.item_trade_list_tv_money_cny_type, "总计:");


        TextView item_trade_list_tv_money_n = (TextView) helper.getView(R.id.item_trade_list_tv_money_n);


        helper.setText(R.id.item_trade_list_tv_money_y, item.getBalance());
        if (Double.valueOf(item.getOrder_margin()) == 0) {
            helper.setText(R.id.item_trade_list_tv_money_n, "0.00");
        } else {
//            helper.setText(R.id.item_trade_list_tv_money_n, Tools.round(Double.valueOf()item.getOrder_margin(), 8).toString().trim());
            helper.setText(R.id.item_trade_list_tv_money_n, Tools.round(Double.valueOf(item.getOrder_margin()), 8).toString().trim());
        }

        if (Double.valueOf(item.getPosition_margin()) == 0) {
            helper.setText(R.id.item_trade_list_tv_total_money, "0.00000000");
        } else {
//            helper.setText(R.id.item_trade_list_tv_total_money, Tools.round(item.getPosition_margin(), 8).toString().trim());
            helper.setText(R.id.item_trade_list_tv_total_money, Tools.round(Double.valueOf(item.getPosition_margin()), 8).toString().trim());
        }

        if (Double.valueOf(item.getTotal()) == 0) {
            helper.setText(R.id.item_trade_list_tv_money_cny, "0.00");
        } else {
//            helper.setText(R.id.item_trade_list_tv_money_cny, Tools.round(item.getTotal(), 2).toString().trim() + "\t" + "CNY");
            helper.setText(R.id.item_trade_list_tv_money_cny, Tools.round(Double.valueOf(item.getTotal()), 8).toString().trim());
        }


        helper.addOnClickListener(R.id.treaty_behavior_tv_change);


    }
}
